package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC874 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int robotSim(int[] commands, int[][] obstacles) {
            int[] xdir = {0, 1, 0, -1};
            int[] ydir = {1, 0, -1, 0};
            Set<String> bar = new HashSet<>();
            for (int i = 0; i < obstacles.length; i++) {
                bar.add(obstacles[i][0] + " " + obstacles[i][1]);
            }
            int xnow = 0;
            int ynow = 0;
            int dirnow = 0;
            int max = 0;
            for (int i = 0; i < commands.length; i++) {
                if (commands[i] > 0) {
                    for (int j = 0; j < commands[i]; j++) {
                        String barkey = (xnow + xdir[dirnow]) + " " + (ynow + ydir[dirnow]);
                        if (bar.contains(barkey)) {
                            break;
                        }
                        xnow += xdir[dirnow];
                        ynow += ydir[dirnow];
                        int dis = xnow * xnow + ynow * ynow;
                        if (dis > max) {
                            max = dis;
                        }
                    }
                }
                if (commands[i] < 0) {
                    if (commands[i] == -1) {
                        dirnow += 1;
                    }
                    if (commands[i] == -2) {
                        dirnow += 3;
                    }
                    dirnow = dirnow % 4;
                }
            }
            return max;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC874 an = new LC874();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
